package com.example.dagger2;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;

import com.example.dagger2.di.Presenter;
import com.example.dagger2.object.DatabaseObject;
import com.example.dagger2.object.HttpObject;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity {


    @Inject
    HttpObject httpObject;
    @Inject
    HttpObject httpObject2;
    @Inject
    DatabaseObject databaseObject;
    @Inject
    DatabaseObject databaseObject2;
    @Inject
    Presenter presenter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //  写这些代码之前一定要先去 Build 里面运行一下 ReBuild Project 不然还没有生成 DaggerMyComponent类和里面的各种方法
//        DaggerMyComponent.create().injectMainActivity(this);
//        上下  两段代码的效果都是一样的
//        DaggerMyComponent.builder()
//                .httpModule(new HttpModule())
//                .databaseModule(new DatabaseModule())
//                .build()
//                .injectMainActivity(this);

        ((MyApplication) getApplication()).getAppComponent()
                        .injectMainActivity(this);

        Log.e("注入成功了", " " + httpObject.hashCode());
        Log.e("注入成功了", " " + httpObject2.hashCode());
        Log.e("注入成功了", " " + databaseObject.hashCode());
        Log.e("注入成功了", " " + databaseObject2.hashCode());
        Log.e("注入成功了", " " + presenter.hashCode());


        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, SecActivity.class));
            }
        });

    }
}